package xcmg.device.service.repair;

import com.google.common.collect.Maps;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xcmg.device.dao.entity.repair.RepairDO;
import xcmg.device.dao.mapper.repair.RepairMapper;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class RepairService {

	@Autowired
	private RepairMapper repairMapper;

	public List<RepairDO> itemByCode(String code) {
		return repairMapper.itemByCode(code);
	}

	public List<RepairDO> queryByCodes(List<String> codes) {
		return repairMapper.itemByCodes(codes);
	}

	public Map<String, List<RepairDO>> queryMapByCodes(List<String> codes) {
		if (CollectionUtils.isEmpty(codes)) {
			return Maps.newHashMap();
		}
		return queryByCodes(codes).stream().collect(Collectors.groupingBy(RepairDO::getRepairCode));
	}
}
